#银行账户信息
cardlist = [{'姓名':'李四', '余额':1000, '密码':12345678},
            {'姓名':'张三', '余额':5000, '密码':66668888},
            {'姓名':'胡二', '余额':9999, '密码':77779999}]

pwdgroup = [12345678, 66668888, 77779999]

#定义操作银行卡的函数：
def showcard(cardlist):
    '''
    对银行卡操作的函数
    '''
    global password
    global i
    print ('|{0:5}|{1:10}|{2:10}|{3:10}|'.format('序号','姓名','余额','密码'))
    print ('-'*60)
    #for i in range(len(cardlist)):
    print ('|{0:<6}|{1:<10}|{2:<12}|{3:<11}|'.format(i+1, cardlist[i]['姓名'], cardlist[i]['余额'], cardlist[i]['密码']))

#登录界面：
#password = 12345678
print()
print()
print('=' * 22, ' 银行管理系统 ', '=' * 22)
print()
print()
for j in range(1,4):
    password = int(input('请输入银行卡密码：'))
    if password not in pwdgroup:
        print('密码不正确，请重新输入!')
        if j == 3:
            print('连续三次输入错误密码！卡已锁定，请联系银行工作人员！')
    else:
        if password == 12345678:
            i = 0
        elif password == 66668888:
            i = 1
        else:
            i = 2
        while True:
            print('='*20,' 欢迎进入银行系统! ', '='*20)
            print('{0:5}{1:30}{2:10}'.format(' ', '1. 查看账户信息', '2. 存款'))
            print('{0:5}{1:30}{2:10}'.format(' ', '3. 修改账户密码', '4. 取款'))
            print('{0:5}{1:30}{2:10}'.format(' ', '5. 用户账户转账', '6. 退出'))
            print('=' * 60)
            key = int(input('请输入对应的选择：'))
            if key == 1:
                print('=' * 22, ' 查看账户信息 ', '=' * 22)
                showcard(cardlist)
                print(input('按回车键继续！'))
            elif key == 2:
                print('=' * 25, '存款', '=' * 25)
                showcard(cardlist)
                c_in =  int(input('请输入存款金额：'))
                cardlist[i]['余额'] += c_in
                showcard(cardlist)
                print(input('按回车键继续！'))
            elif key == 3:
                print('=' * 22, '修改账户密码', '=' * 22)
                showcard(cardlist)
                #c_in =  int(input('请输入存款金额：'))
                passwd_0 = input('请输入新密码：')
                passwd_1 = input('请确认新密码：')
                if passwd_0 == passwd_1:
                    cardlist[i]['密码'] = int(passwd_0)
                    showcard(cardlist)
                else:
                    print (input('两次输入密码不一致！！！'))
                print(input('按回车键继续！'))
            elif key == 4:
                print('=' * 25, '取款', '=' * 25)
                showcard(cardlist)
                c_out =  int(input('请输入取款金额：'))
                while c_out > cardlist[i]['余额']:
                    print ('账户余额不足，请重新输入！')
                    c_out = int(input('请输入取款金额：'))
                cardlist[i]['余额'] -= c_out
                showcard(cardlist)
                print(input('按回车键继续！'))
            elif key == 5:
                print('=' * 24, ' 用户账户转账 ', '=' * 24)
                showcard(cardlist)
                c_out = int(input('请输入转出金额：'))
                while c_out > cardlist[i]['余额']:
                    print ('账户余额不足，请重新输入！')
                    c_out = int(input('请输入转出金额：'))
                cardlist[i]['余额'] -= c_out
                showcard(cardlist)
                print(input('按回车键继续！'))
            elif key == 6:
                print('=' * 28, '再见', '=' * 27)
                break
            else:
                print('无效的输入！')
                print(input('按回车键继续！'))
        break
